﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ReturnsOrder.aspx.cs" Inherits="UI_Bas_ReturnsOrder" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>退货单管理</title>
    <script src="../../js/common.js" type="text/javascript"></script>
    <link href="../../css/admin.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery.easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery.easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery.easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../js/FileUpload/ajaxfileupload.js" type="text/javascript"></script>
  
    <script type ="text/javascript" >
        $(function () {

            $("#ddlProcessingStatus").combobox({
                editable: false
            });
            var defaultDate = Date.parse('1900/01/01');
            var _$returnsOrder = $("#returnsOrder");
            _$returnsOrder.datagrid({
                border: true,
                height: 345,
                width: 1100,
                title: '退货单列表...',
                remoteSort: false,
                nowrap: true,
                striped: false,
                //url: "../../TableHanders.aspx?act=q&tid=43&type=0",
                sortName: 'returnsOrderId',
                sortOrder: 'desc',
                loadMsg: "正在加载,请稍后...",
                frozenColumns: [[
                    { title: 'ck', field: 'CheckId', checkbox: true },
	                { title: '退货单号', field: 'ReturnsOrderId', width: 180, sortable: true,
	                    formatter: function (val, row, index) {
	                        var isMatch = row.IsMatch;
	                        if (isMatch == 1) {
	                            return '<span style="color:red;">' + val + '</span>';
	                        }
	                        else {
	                            return val;
	                        }
	                    }
	                },
	                { title: 'ebay帐号', field: 'EbayUserId', width: 200, sortable: true },
	                { title: '订单号', field: 'OrderId', width: 150, sortable: true }
				  ]],
                columns: [[
                    { title: 'FitemId', field: 'FitemId', width: 100, sortable: true },
	                { title: '处理情况', field: 'ProcessingStatus', width: 90, sortable: true, formatter: function (val) {
	                    if (val == 0) {
	                        return '未处理';
	                    }
	                    else if (val == 1) {
	                        return '<span style="color:red;">重发</span>';
	                    }
	                    else if (val == 2) {
	                        return '<span style="color:red;">退款</span>';
	                    }
	                    else if (val == 3) {
	                        return '<span style="color:red;">待定</span>';
	                    }
	                    else {
	                        return val;
	                    }
	                }
	                },
	                { title: '是否匹配', field: 'IsMatch', width: 80, sortable: true, formatter: function (val) {
	                    if (val == 0) {
	                        return '未匹配';
	                    }
	                    else if (val == 1) {
	                        return '已匹配';
	                    }
	                    else {
	                        return val;
	                    }
	                }
	                },
	                { title: '同步日期', field: 'SynchronousDate', width: 120, sortable: true, formatter: function (val) {
	                    var d = Date.parse(val.replace("-", "/"));
	                    if (d == defaultDate) {
	                        return "";
	                    }
	                    else {
	                        return val;
	                    }
	                }
	                },
	                { title: '摘要', field: 'Remarks', width: 280, sortable: true }
				]],
                pagination: true,
                rownumbers: true,
                singleSelect: true,
                pageList: [10, 15, 20],
                queryParams: {
                    "timeFrom": $("#dateFrom").datebox('getValue'),
                    "timeTo": $("#dateTo").datebox('getValue'),
                    "processingStatus": $("#ddlProcessingStatus").combobox('getValue'),
                    "Remarks": $("#searchRemarks").val()
                },
                onDblClickRow: function (rowIndex, rowData) {
                    var ReturnsOrderId = rowData.ReturnsOrderId;
                    var FitemId = rowData.FitemId;
                    _$returnsOrder.datagrid('clearSelections');
                    _$returnsOrder.datagrid('selectRow', rowIndex);
                    RefreshTab(ReturnsOrderId, FitemId);
                }
            });

            $("#btnQuery").click(function () {
                $('#datadiv').panel('open');
                if (!$("#divContent").form('validate'))
                    return;
                var processingStatus = $("#ddlProcessingStatus").combobox('getValue');
                var timeFrom = $("#dateFrom").datebox('getValue');
                var timeTo = $("#dateTo").datebox('getValue');
                var remarks = $("#searchRemarks").val();
                _$returnsOrder.datagrid({
                    url: "../../TableHanders.aspx?act=q&tid=43&type=0",
                    queryParams: {
                        "processingStatus": processingStatus,
                        "timeFrom": timeFrom,
                        "timeTo": timeTo,
                        "Remarks": remarks
                    }
                });
            });
            $('#dateFrom').datebox({ formatter: function (date) {
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                var d = date.getDate();
                return y + "-" + m + "-" + d;
            }
            });
            $('#dateTo').datebox({ formatter: function (date) {
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                var d = date.getDate();
                return y + "-" + m + "-" + d;
            }
            });


            //同步K3
            $("#btnSynchronousK3").click(function () {
                var url = getRootPath() + "/UI/Orders/OrdersHandler.ashx?cmd=thdtbu&ts=" + new Date().getTime();
                $.getJSON(url, function (data) {
                    var retData = EvalData(data);
                    var code = retData.retCode;
                    if (code == 0) {
                        alert("退货单同步完成!!..");
                        _$returnsOrder.datagrid('reload');
                    }
                    else {
                        alert(retData.retMsg);
                    }
                });
            });

            //导入
            $("#btnImPort").click(function () {
                var file = $("#fup");
                var filePath = getPath(file);
                if (filePath == "") {
                    alert("请选择一个excel文件");
                    return;
                }
                var strRegex = "(.csv)$";
                var re = new RegExp(strRegex);

                if (!re.test(filePath)) {
                    alert("只支持*.csv文件");
                    clearvalue(file);
                    return;
                }
                ajaxFileUploads();
            });

            //退货单——处理
            $("#btncli").click(function () {
                var rows = _$returnsOrder.datagrid('getSelections');
                if (rows.length == 0) {
                    alert('请选择一个退货单');
                    return;
                }
                if (rows.length != 1) {
                    alert('只能选择一退货单!');
                    return;
                }
                var oStatusId = rows[0].ProcessingStatus;
                if (oStatusId != 0) {
                    alert("只有未处理的退货单才可以处理！..");
                    return;
                }
                $("#txtReturnsOrderId").val(rows[0].ReturnsOrderId);
                $("#txtRemarks").val(rows[0].Remarks);
                $("#txtFitemId").val(rows[0].FitemId);
                $("#ReturnsOrderWindow").window('open');
            });

            //tab明细
            $('#tabs').tabs({
                height: 200,
                width: 1100
            });

            //退货单维护窗口
            $("#ReturnsOrderWindow").window({
                width: 400,
                height: 235,
                modal: true,
                shadow: false,
                closed: true,
                collapsible: false,
                minimizable: false,
                maximizable: false
            });

            // 退货单处理取消
            $("#btnReturnCancel").click(function () {
                $("#ReturnsOrderWindow").window('close');
            });
            //退货单处理确定
            $("#btnReturnOK").click(function () {
                var ebayuserId = $("#ddlebayUserId").val();
                var rec_number = $("#txtOrderLineItemId").val();
                var returnorderId = $("#txtReturnsOrderId").val();
                var proStatus = $("#ddlProStatus").val();
                var remarks = $("#txtRemarks").val();
                var fitemId = $("#txtFitemId").val();
                var url = getRootPath() + "/UI/Orders/OrdersHandler.ashx?cmd=thdchuli&ebayid=" + ebayuserId + "&rec=" + rec_number + "&rid=" + returnorderId + "&fitemId=" + fitemId + "&proStatus=" + proStatus + "&remarks=" + encodeURIComponent(remarks); +"&ts=" + new Date().getTime();
                $.getJSON(url, function (data) {
                    var retData = EvalData(data);
                    var code = retData.retCode;
                    if (code == 0) {
                        alert("退货单处理成功!!");
                        $('#ReturnsOrderWindow').window('close');
                        _$returnsOrder.datagrid("clearSelections");
                        _$returnsOrder.datagrid('reload');
                    }
                    else {
                        alert(retData.retMsg);
                    }
                });
            });
        });

        function RefreshTab(ReturnsOrderId, FitemId) {
            LoadProductDetail(ReturnsOrderId,FitemId);
        }
        //商品明细
        function LoadProductDetail(ReturnsOrderId,FitemId) {
            var _$tproduct = $("#tproduct");
            _$tproduct.datagrid({
                border: true,
                height: 165,
             // title: '商品明细...',
                remoteSort: false,
                nowrap: true,
                striped: false,
                border: false,
                rownumbers: true,
                singleSelect: true,
                url: "../../TableHanders.aspx?act=q&tid=1022&type=0",
                loadMsg: "正在加载,请稍后...",
                frozenColumns: [[
                                { title: '退货单号', field: 'ReturnsOrderId', width: 150, sortable: true },
                                { title: '商品编号', field: 'ProductId', width: 150, sortable: true }                                                                
                               ]],
                columns: [[
                                { title: 'FitemId', field: 'FitemId', width: 100, sortable: true },
                                { title: '商品名称', field: 'ProductName', width: 260, sortable: true },
                                { title: '商品规格', field: 'ProductSpecification', width: 180, sortable: true },
                                { title: '商品数量', field: 'FQty', width: 130, sortable: true },
                                { title: '商品单价', field: 'FPrice', width: 130, sortable: true },
                                { title: '商品总价', field: 'FAmount', width: 80, sortable: true }
                                ]],
                queryParams: {
                    "ReturnsOrderId": ReturnsOrderId,
                    "FitemId": FitemId
                }
            });
        } 
        function ajaxFileUploads() {
        $.ajaxFileUpload(
                {
                    url: '../../UpLoadFile.ashx?type=excel&tid=43&id=' + new Date().getTime(),
                    secureuri: false,
                    fileElementId: 'fup',
                    dataType: 'text',
                    success: function (data, status) {
                        var retData = EvalData(data);
                        if (retData.retCode = 0) {
                            alert('成功导入!');
                        }
                        else {
                            alert(retData.retMsg);
                        }
                    },
                    error: function (data, status, e) {
                        alert("更新失败!");
                    }
                });
        }              
        

	</script>	
</head>
<body>
 <form id="formQuery" runat="server">
      <div class="div_Title">
            <span class="Body_Title">》》<%=this.Title %></span>
      </div>  
      <div id="divContent" class="easyui-panel" title="请输入查询条件..." style="margin-bottom:5px; width :1100px;">   
             <table id="tabquery" style ="margin-bottom :5px; margin-top :5px; margin-left :20px;">
                 <tr>           
                    <td> 处理状态:</td> 
                    <td>                   
                        <select id="ddlProcessingStatus" runat="server" class="easyui-validatebox" enableviewstate="false" style ="width :110px;"/></td>               
                    <td>同步日期:</td>
                    <td>
                        <input type ="text" ID ="dateFrom" runat="server" class ="easyui-datebox" required="true" style ="width :120px;"  /></td>                  
                    <td> - </td>
                    <td>
                        <input type ="text" ID="dateTo"  runat="server" class ="easyui-datebox" required="true" style ="width :120px;" /></td>
                    <td>摘要:</td>
                    <td><input type = 'text' id = 'searchRemarks' runat = 'server'  style ='width :240px;'/></td>
                    <td> 
                        <a id="btnQuery"  href ="#"  class="easyui-linkbutton" icon="icon-search" >Query</a></td>
                </tr>
            </table> 
      </div>
      <div id ="divOperating" class="easyui-panel" title="操作区域" style="width :1100px;">
           <table style="margin-left :20px;" >
               <tr>
                    <td>选择文件:</td>
                    <td>
            	        <input type="file" id="fup" name="fup" style="width:500px"/>
                    </td>
                    <td>
                    <a id="btnImPort" class = "easyui-linkbutton"  icon="icon-reload">导入</a></td>
                <%--<td  style =" width :120px; text-align :center;" >                  
                    <a id="btnSynchronousK3"  href ="#"  class="easyui-linkbutton" >同步K3</a></td>--%>
                <%--<td style =" width :120px; text-align :center;" >
                    <a id ="btncli" href ="#" class = "easyui-linkbutton" >处 理</a></td>--%>
              </tr>
            </table>
      </div>      
      <table id="returnsOrder" ></table>      
      <div id="tabs" style="margin-top:5px;">
            <div id="divspmxi" title="退货单商品明细">
                <table id="tproduct"></table>   
            </div>
       </div>
       <div id = "ReturnsOrderWindow" title = "退货单信息维护">
          <div id ="returndetaildiv">
               <table>
                     <tr>
                        <td >退货单号：</td>
                        <td >
                            <input type="text" id="txtReturnsOrderId" runat="server" class="easyui-validatebox"  readonly="readonly" style="width :200px;" />
                            <input type="hidden" id="txtFitemId" />
                        </td>
                    </tr>
                     <tr>
                        <td >Rec_Num：</td>
                        <td >
                            <input type="text" id="txtOrderLineItemId" runat="server" class="easyui-validatebox" required = "true" style="width :200px;"/>
                        </td>
                    </tr>
                     <tr>
                        <td >ebay帐号：</td>
                        <td >                   
                             <select id="ddlebayUserId" runat="server" class="easyui-validatebox" enableviewstate="false" style ="width :206px;"/>
                        </td>
                    </tr>
                    <tr>
                        <td >处理情况：</td>
                        <td >
                             <select id="ddlProStatus" runat="server" class="easyui-validatebox" enableviewstate="false" style ="width :206px;"/>
                        </td>
                    </tr> 
                    <tr>
                        <td >备注：</td>
                        <td >
                          <input type="text" id="txtRemarks" runat="server" class="easyui-validatebox" style="width :200px;" />
                        </td>
                    </tr>
               </table> 
           </div>
          <div style="text-align:right;height:30px;line-height:30px; padding:10px;">
			    <a id="btnReturnOK" class="easyui-linkbutton" iconCls="icon-ok" href="javascript:void(0)" >匹配</a>
			    <a id="btnReturnCancel" class="easyui-linkbutton" iconCls="icon-cancel" href="javascript:void(0)">返回</a>
		  </div>     
      </div>
   </form>  
</body>
</html>